package com.gsit.expenditure.client.domina;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import com.gsit.expenditure.domain.Bill;
import com.gsit.expenditure.domain.Invoice;
import com.gsit.expenditure.utils.InvoiceStatus;

public class InvoiceBean implements BeanHendler<Invoice> {

	private StringProperty invoiceNumber = new SimpleStringProperty("");
	private ObjectProperty<Date> createdDate = new SimpleObjectProperty<Date>();
	private StringProperty customerName = new SimpleStringProperty("");
	private StringProperty fromDate = new SimpleStringProperty();
	private StringProperty toDate = new SimpleStringProperty();
	private StringProperty allValues = new SimpleStringProperty("");
	private StringProperty status=new SimpleStringProperty("");

	private Invoice invoice;

	private InvoiceBean() {

	}
	
	public InvoiceBean(Invoice invoice) {
		if (invoice == null) {
			invoice = new Invoice();
		}
		this.invoice = invoice;
		init(invoice);
	}
	
	public Invoice getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}

	@Override
	public void init(Invoice invoice) {
		if (invoice != null) {
		   invoiceNumber.setValue(invoice.getInvoiceNumber());
		   createdDate.setValue(invoice.getCreatedDate());
		   if(invoice.getStatus()!= null)
		      status.setValue(invoice.getStatus().toString());
		   
		   if(invoice.getBills()!= null)
		      customerName.setValue(invoice.getBills().iterator().next().getCustomer().getFirstName());
		// vehicle.setValue(invoice.getVehicle());
		}
	}

	@Override
	public void reLoad(Invoice invoice) {
		this.invoice = invoice;
		init(invoice);
	}

	@Override
	public void clean() {
		
	}

	@Override
	public Invoice getObject() {


		
		if(this.invoice == null){
			this.invoice = new Invoice();
		}
		
		invoice.setCreatedDate(createdDate.getValue());
		//invoice.setStatus(InvoiceStatus.valueOf(status.getValue()));
		invoice.setInvoiceNumber(invoiceNumber.getValue());
		Set<Bill> bills = new HashSet<>();
		invoice.setBills(bills);

		return invoice;
	}
	

	public String getInvoiceNumber() {
		return invoiceNumber.get();
	}
	public void setInvoiceNumber(String invoiceNumber) {
		this.invoiceNumber.set(invoiceNumber);
	}

	public StringProperty getFromDate() {
		return fromDate;
	}
	public void setFromDate(StringProperty fromDate) {
		this.fromDate = fromDate;
	}
	public StringProperty getToDate() {
		return toDate;
	}
	public void setToDate(StringProperty toDate) {
		this.toDate = toDate;
	}
	

	public Date getCreatedDate() {
		return createdDate.get();
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate.set(createdDate);
	}
	public String getStatus() {
		return status.get();
	}
	public void setStatus(String status) {
		this.status.set(status);
	}
	
	public void setCustomerName(String customerName) {
		this.customerName.set(customerName);
	}
	public String getCustomerName() {
		return customerName.get();
	}


	
}
